#-*- coding: utf-8 -*-

import sys
from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets

class MyMainWindow(QtWidgets.QMainWindow):
    def __init__(self,parent=None):
        #继承父类
        QtWidgets.QMainWindow.__init__(self,parent)
        #自定义布局函数
        self.initUI()



    def initUI(self):
        # 窗口标题
        self.setWindowTitle("MainWindow")
        #窗口大小
        self.resize(400,400)
        self.pixMap=QtGui.QPixmap(300,300)
        self.pixMap.fill(QtCore.Qt.white)


    def paintEvent(self, event):
        painter= QtGui.QPainter(self.pixMap)
        transform=QtGui.QTransform()
        transform.rotate(10)
        transform.scale(0.8,0.8)
        painter.setTransform(transform)
        painter.translate(100,100)
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
        painter.setPen(QtGui.QPen(QtCore.Qt.red,2,QtCore.Qt.DashDotLine))
        painter.setBrush(QtCore.Qt.CrossPattern)
        painter.setFont(QtGui.QFont("宋体",40,100,True))
        painter.drawText(QtCore.QPoint(0,0),"China")

        painter.setPen(QtGui.QPen(QtCore.Qt.blue,1))
        painter.drawLine(20,20,220,220)
        painter.drawLine(20,220,220,20)
        painter.drawEllipse(20,20,200,200)
        painter.drawRect(20,20,200,200)

        painter.end()

        painter.begin(self)
        painter.drawPixmap(QtCore.QPoint(50,50),self.pixMap)

if __name__ == "__main__":
    app=QtWidgets.QApplication(sys.argv)
    myMainWindow=MyMainWindow()
    myMainWindow.show()
    sys.exit(app.exec_())